/**
 * 文件转 base64
 * @param file
 * @returns
 */
export function fileToBase64(file: Blob): Promise<string> {
  return new Promise<string>((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => {
      resolve(reader.result as string)
    }
    reader.onerror = (error) => {
      reject(error)
    }
  })
}

/**
 * 给一个URL添加前缀，生成一个完整的URL字符串
 * @param url
 * @returns
 */
export function getFullUrl(url: string) {
  if (!url) {
    return url
  }
  if (url.startsWith("http://") || url.startsWith("https://")) {
    return url
  }
  return import.meta.env.VITE_BASE_URL + url
}
